﻿#region License
/*

	Copyright (C) 2008 Oliver Charles, Daniel Hollander

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
	
*/
#endregion

namespace Overload.AI
{
    /// <summary>
    /// A node is similar to a tile in the world, except that it can have a <see cref="Parent"/>. This
    /// allows nodes to be chained together to create a path.
    /// </summary>
    internal class Node
    {
        #region Properties

        private readonly ITile tile;
        private Node parent;
        private float g, h;

        /// <summary>
        /// The tile that this node is connected to.
        /// </summary>
        public ITile Tile
        {
            get { return tile; }
        }

        /// <summary>
        /// The "parent" of this node - which node preceeds it in a path.
        /// </summary>
        public Node Parent
        {
            get { return parent; }
            set { parent = value; }
        }

        /// <summary>
        /// The G part of the heuristic
        /// </summary>
        public float G
        {
            get { return g; }
            set { g = value; }
        }

        /// <summary>
        /// The H part of the heuristic
        /// </summary>
        public float H
        {
            get { return h; }
            set { h = value; }
        }

        /// <summary>
        /// The total cost of this node - F ( = G + H). This also adds a tie breaker
        /// </summary>
        public float Cost
        {
            get { return G + (H * 1.0001f); }
        }

        #endregion
        #region Constructors

        /// <summary>
        /// Construct a new <see cref="Node"/>, bound to a specific <see cref="ITile"/>.
        /// </summary>
        /// <param name="tile"></param>
        public Node(ITile tile)
        {
            this.tile = tile;
        }

        #endregion
    }
}